<?php

require('spider.config.php');

$group_id = $_GET['type'];

/******************************************************************************
 * Groups
**/

$groups = array(
    'front-css' => array(
        SPIcfg::$dir['styles'].'front/css/common.css',
        SPIcfg::$dir['styles'].'front/css/titles.css',
        SPIcfg::$dir['styles'].'front/css/list-content-item.css',
        SPIcfg::$dir['styles'].'front/css/catalogs.css',
        SPIcfg::$dir['styles'].'front/css/buttons.css',
        SPIcfg::$dir['styles'].'front/css/content-params.css',
        SPIcfg::$dir['styles'].'front/css/content-filters.css',
        SPIcfg::$dir['styles'].'front/js/shadowbox/shadowbox.css',
    ),

    'front-js' => array(
        SPIcfg::$dir['styles'].'front/js/jquery-1.3.2.min.js',
        SPIcfg::$dir['styles'].'front/js/common.js',
        SPIcfg::$dir['styles'].'front/js/hot_keys.js',
    ),

    'manage-css' => array(
        SPIcfg::$dir['styles'].'manage/css/manage.css',
        SPIcfg::$dir['styles'].'manage/css/objHeader.css',
        SPIcfg::$dir['styles'].'manage/css/cntView.css',
        SPIcfg::$dir['styles'].'manage/css/cntForm.css',
        SPIcfg::$dir['styles'].'manage/css/cntMedia.css',
        SPIcfg::$dir['styles'].'manage/css/icons.css',
        SPIcfg::$dir['styles'].'manage/css/objFormdecor.css',
        SPIcfg::$dir['styles'].'manage/css/objMainmenu.css',
        SPIcfg::$dir['styles'].'manage/css/stdobj.css',
        SPIcfg::$dir['styles'].'manage/css/buggy.css',
        SPIcfg::$dir['styles'].'manage/css/jquery-ui.css',
    ),

    'manage-js' => array(
        SPIcfg::$dir['styles'].'manage/js/jquery-1.3.2.min.js',
        SPIcfg::$dir['styles'].'manage/js/jquery-ui.js',
        SPIcfg::$dir['styles'].'manage/js/jquery-ui.sortable.min.js',
        SPIcfg::$dir['styles'].'manage/js/jquery.form.js',
        SPIcfg::$dir['styles'].'manage/js/cntForm.js',
        SPIcfg::$dir['styles'].'manage/js/cntMedia.js',
        SPIcfg::$dir['styles'].'manage/js/buggy.js',
        SPIcfg::$dir['styles'].'manage/js/manage.js',
    ),
);

if( isset( $groups[ $group_id ] ) === false )
{
    die('Undefined source ID');
}

/******************************************************************************
 * Minify-config
**/

    /**
     * Path to Minify's lib folder. If you happen to move it, change
     * this accordingly.
     */
    $min_libPath = SPIcfg::$util['minify']['basedir'];

    /**
     * For best performance, specify your temp directory here. Otherwise
     * Minify will have to load extra code to guess. Commented out below
     * are a few possible choices.
     */
    $min_cachePath = SPIcfg::$util['minify']['cache_basedir'];

    /**
     * Cache file locking. Set to false if filesystem is NFS.
     */
    $min_cacheFileLocking = true;

    /**
     * Allow use of the Minify URI Builder app. If you no longer need
     * this, set to false.
     **/
    $min_enableBuilder = true;

    /**
     * Maximum age of browser cache in seconds. After this period,
     * the browser will send another conditional GET. You might
     * want to shorten this before making changes if it's crucial
     * those changes are seen immediately.
     */
    $min_serveOptions['maxAge'] = 10 * 365 * 24*60*60; // 1800;

    /**
     * If you'd like to restrict the "f" option to files within/below
     * particular directories below DOCUMENT_ROOT, set this here.
     * You will still need to include the directory in the
     * f or b GET parameters.
     *
     * // = DOCUMENT_ROOT
     */
    //$min_serveOptions['minApp']['allowDirs'] = array('//js', '//css');

    /**
     * Set to true to disable the "f" GET parameter for specifying files.
     * Only the "g" parameter will be considered.
     */
    $min_serveOptions['minApp']['groupsOnly'] = false;

    /**
     * Maximum # of files that can be specified in the "f" GET parameter
     */
    $min_serveOptions['minApp']['maxFiles'] = 10;

    /**
     * If you upload files from Windows to a non-Windows server, Windows may report
     * incorrect mtimes for the files. This may cause Minify to keep serving stale
     * cache files when source file changes are made too frequently (e.g. more than
     * once an hour).
     *
     * Immediately after modifying and uploading a file, use the touch command to
     * update the mtime on the server. If the mtime jumps ahead by a number of hours,
     * set this variable to that number. If the mtime moves back, this should not be
     * needed.
     *
     * In the Windows SFTP client WinSCP, there's an option that may fix this
     * issue without changing the variable below. Under login > environment,
     * select the option "Adjust remote timestamp with DST".
     * @link http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time
     */
    $min_uploaderHoursBehind = 0;

    // try to disable output_compression (may not have an effect)
    ini_set('zlib.output_compression', '0');

/******************************************************************************
 * Exec
**/

    define('MINIFY_MIN_DIR', dirname(__FILE__) );

    set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());

    require $min_libPath . 'Minify.php';

    Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
    Minify::setCache(
        isset($min_cachePath) ? $min_cachePath : null
        ,$min_cacheFileLocking
    );

    if( 0 === stripos(PHP_OS, 'win') )
    {
        Minify::setDocRoot(); // we may be on IIS
    }

    $min_serveOptions['group_id'] = $group_id;
    $min_serveOptions['minApp']['groups'] = $groups;

    if (preg_match('/&\\d/', $_SERVER['QUERY_STRING']))
    {
        $min_serveOptions['maxAge'] = 31536000;
    }

    Minify::serve('MinApp', $min_serveOptions);

?>